package com.hkh.erp.common.api;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;

@ApiModel(value = "接口返回结果",description = "接口返回结果")
public class RespResult<T> {

    @ApiModelProperty(value = "返回状态：0成功，1失败，2token过期，3token非法，4非法用户")
    private int code;

    @ApiModelProperty(value = "返回信息")
    private String message;

    @ApiModelProperty(value = "返回结果数据")
    private T result;

    public RespResult(int code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public RespResult() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public  RespResult ok(){
        return new RespResult(RespStatus.SUCCESS.getCode(),RespStatus.SUCCESS.getDescribe(),null);
    }

    public  RespResult ok(T data){
        return new RespResult(RespStatus.SUCCESS.getCode(),RespStatus.SUCCESS.getDescribe(),data);
    }

    public  RespResult ok(String msg,T data){
        return new RespResult(RespStatus.SUCCESS.getCode(),msg,data);
    }

    public  RespResult fail(){
        return new RespResult(RespStatus.ERROR.getCode(),RespStatus.ERROR.getDescribe(),null);
    }

    public  RespResult fail(String msg){
        return new RespResult(RespStatus.ERROR.getCode(),msg,null);
    }

    public  RespResult fail(String msg,T data){
        return new RespResult(RespStatus.ERROR.getCode(),msg,data);
    }

    public  RespResult userInvalid(){
        return new RespResult(RespStatus.USER_INVALID.getCode(),RespStatus.USER_INVALID.getDescribe(),null);
    }

    public  RespResult userInvalid(String msg){
        return new RespResult(RespStatus.USER_INVALID.getCode(),msg,null);
    }

    public  RespResult tokenInvalid(){
        return new RespResult(RespStatus.TOKEN_INVALID.getCode(),RespStatus.TOKEN_INVALID.getDescribe(),null);
    }

    public  RespResult tokenInvalid(String msg){
        return new RespResult(RespStatus.TOKEN_INVALID.getCode(),msg,null);
    }

    public  RespResult tokenExpired(){
        return new RespResult(RespStatus.TOKEN_EXPIRED.getCode(),RespStatus.TOKEN_EXPIRED.getDescribe(),null);
    }

    public  RespResult tokenExpired(String msg){
        return new RespResult(RespStatus.TOKEN_EXPIRED.getCode(),msg,null);
    }
}
